﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;
using Antu.Core.DataAccess;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZJ_DZJEControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            if (!base.Page.IsPostBack)
            {
                BindData();
            }
            CustomGridView CustomGridView1 = (CustomGridView)FindControl("CustomGridView1");
            CustomGridView1.OnLoadData += new EventHandler(CustomGridView1_OnLoadData);
            CustomGridView1.RowDeleting += new GridViewDeleteEventHandler(CustomGridView1_RowDeleting);
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            Label labYe = (Label)FindControl("labYe");
            string strbid = base.Page.Request["ID"];
            string tt = _EluZSDataProvider.GetNowYE(strbid);
            labYe.Text = "当前余额为：" + string.Format("{0:N}", double.Parse(tt));
        }
        private void BindData()
        {
            CustomGridView CustomGridView1 = (CustomGridView)FindControl("CustomGridView1");
            string strBID = base.Page.Request["ID"];
            if (!string.IsNullOrEmpty(strBID))
            {
                DataTable dt = _EluZSDataProvider.GetDZJE(strBID);
                CustomGridView1.DataSource = dt;
                CustomGridView1.RecordCount = dt.Rows.Count;
                CustomGridView1.HideColName = "id";
                CustomGridView1.DataKeyNames = new string[] { "ID" };
                CustomGridView1.DataBind();
            }
        }
        protected void CustomGridView1_OnLoadData(object sender, EventArgs e)
        {
            BindData();
        }
        protected void CustomGridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            CustomGridView CustomGridView1 = (CustomGridView)FindControl("CustomGridView1");
            string dzid = CustomGridView1.DataKeys[e.RowIndex].Value.ToString();
            bool del = _EluZSDataProvider.DeleteXmByID("ZS_NEW_MONEY", "ID", dzid);
            if (del)
            {
                BindData();
                base.Page.Response.Write("<script>alert('删除成功！');window.location.href=location.href;</script>");
            }
        }
    }
}


